package cn.seaboot.admin.user.web;

import cn.seaboot.admin.mvc.Pagination;
import cn.seaboot.admin.mvc.Result;
import cn.seaboot.admin.mvc.argument.Params;
import cn.seaboot.admin.user.bean.User;
import cn.seaboot.admin.user.bean.UserDept;
import cn.seaboot.admin.user.service.UserDeptService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 用户分组 @author Mr.css on 2018-6-20
 */
@Controller
@Tag(name = "用户分组 [t_sys_user_dept] 管理")
@RequestMapping("sys/dept")
public class UserDeptCtrl {

    @Resource
    private UserDeptService userDeptService;

    /**
     * 分组目录
     */
    @ResponseBody
    @Operation(description = "用户分组 [t_sys_user_dept] 增")
    @RequestMapping(value = "info", method = RequestMethod.POST)
    public UserDept addDir(@Params String pid) {
        return userDeptService.insert(pid);
    }

    /**
     * 分组目录
     */
    @ResponseBody
    @Operation(description = "用户分组 [t_sys_user_dept] 删")
    @RequestMapping(value = "info", method = RequestMethod.DELETE)
    public Result deleteDir(@Params String id) {
        return userDeptService.deleteById(id);
    }

    /**
     * 分组目录
     */
    @ResponseBody
    @Operation(description = "用户分组 [t_sys_user_dept] 改")
    @RequestMapping(value = "info", method = RequestMethod.PUT)
    public int updateDir(@Params String id,
                         @RequestParam(defaultValue = "") String icon, UserDept group) {
        return userDeptService.updateById(id, group);
    }

    /**
     * 分组目录
     */
    @ResponseBody
    @Operation(description = "用户分组 [t_sys_user_dept] 查询列表")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public List<UserDept> list() {
        return userDeptService.selectList();
    }


    /**
     * 查询列表
     *
     * @param params 参数
     * @return list
     */
    @ResponseBody
    @Operation(description = "用户分组 [t_sys_user_dept] 查询列表")
    @Parameters({
            @Parameter(name = "page", description = "页号"),
            @Parameter(name = "limit", description = "行数")})
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public PageInfo<UserDept> queryPage(@RequestParam Map<String, Object> params) {
        return Pagination.apply(params, map-> userDeptService.selectList(map));
    }
}
